package cn.like.satoken.token;

import cn.dev33.satoken.action.SaTokenActionDefaultImpl;
import cn.like.satoken.jwt.JwtManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * desc: 重写 创建token的方法
 *
 * @author like 980650920@qq.com
 * @date 2021/7/16 8:14
 */
@Component
@Slf4j
public class TokenAction extends SaTokenActionDefaultImpl {

    private final JwtManager jwtUtil;

    public TokenAction(JwtManager jwtUtil) {this.jwtUtil = jwtUtil;}

    /**
     * 创建令牌
     *
     * @param loginId   用户id
     * @param loginType 登录类型
     * @return {@link String}
     */
    @Override
    public String createToken(Object loginId, String loginType) {
        final String token = jwtUtil.create(loginId);

        log.info("[ 创建token ] userID:{},token:\n{}", loginId, token);
        return token;
    }
}
